const App = {
  mixins: [Query],//配置文件，路径/utils/mixins.js
  data() {
    return {
      teeed: "",
      treeData: [], //树的数据
      originalTreeData: [], //原始树的数据
    };
  },
  mounted() {
    this.Treedata();
  },
  methods: {
    //换届补选按钮，跳转到组织架构页面
    structureAdd() {
      // window.location.href = "structure.html";
    },
    //换届登记按钮，跳转到添加换届领导班子页面
    leaderAdd(row) {
      console.log('20',row);
      console.log('22',row.Work_Team_Member_SerialNumber);
      
      let { primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
      window.location.href = "./workpeople.html?action=Add&nodeKey=" + row.Work_Team_Member_SerialNumber;
      
    },
    //换届编辑按钮，跳转到修改换届页面
    tenureEdit() {
      window.location.href = "tenureEdit.html";
    },
    handleDelete(index, row) {
      console.log(row);

      const that = this;
      this.$confirm("警告！此操作将删除该操作员, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          row.Row_Status = "1";
          $.ajax({
            headers: requestHeaders(),
            url: `${mh}/clientOperation/generalSaveForClient`,
            type: "POST",
            data: {
              Data: JSON.stringify({
                Modify: { work_teams_members: [row] },
              }),
            },
            success: function (res) {
              if (res.Status === "success") {
                that.$message({
                  type: "success",
                  message: "删除成功!",
                });
                that.getList();
              } else {
                that.$message.error("删除失败，请稍后再试");
              }
            },
            complete: (XMLHttpRequest) => {
              requestPretreatment(XMLHttpRequest);
            },
            dataType: "json",
          });
        })
        .catch(() => { });
    },
   

    //树的数据
    Treedata() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        url: mh+"/generalBusiness/getPartyOrganizationTree",
        method: "get",
        success: function (data) {
          console.log(data);
          _this.treeData = data;
          // 使用深拷贝赋值 originalTreeData
          _this.originalTreeData = JSON.parse(JSON.stringify(data));
        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },

    //过滤树的数据
    filterTreeData(data, searchText) {
      return data.filter((item) => {
        if (item.label.includes(searchText)) {
          return true;
        }
        if (item.children) {
          const filteredChildren = this.filterTreeData(
            item.children,
            searchText
          );
          if (filteredChildren.length > 0) {
            item.children = filteredChildren;
            return true;
          }
        }
        return false;
      });
    },

    //树的点击事件
    handleNodeClick(data) {
      console.log(data);
      let arr = [];
      this.Organization(data.children, arr);
      let str = '';
      [data.Party_Organization_SerialNumber, ...arr].forEach(item => {
        if (str) {
          str += "\r\nOR A.Party_Organization_SerialNumber='" + item + "'";
        } else {
          str = "\r\nA.Party_Organization_SerialNumber='" + item + "'";
        }
      })

      if (str) {
        str = "AND (" + str + ")"
      }
      this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent(this.page.ExtensionCondition1 + str)));
      this
      // this.page.Condition = window.btoa(unescape(encodeURIComponent(this.value2+","+this.value2+",%"+data.Party_Organization_SerialNumber+"%,%"+this.input+"%")));
      this.postgetList(this.page);
    },
    Organization(data, arr) {
      data.forEach(item => {
        arr.push(item.Party_Organization_SerialNumber);
        if (item.children && item.children.length > 0) {
          this.Organization(item.children, arr);
        }
      })
    },

  },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
